package com.itedge.infrastructure.service.domain;

import java.util.List;

/**
 * Interface for all services operating with Entities.
 * 
 * @author jhe
 *
 * @param <E>
 */
public interface IEntityService<E> {
	
	/**
	 * Persist entity to underlying database.
	 * 
	 * @param entity
	 */
	public void persist(E entity);

	/**
	 * Remove entity from underlying database.
	 * 
	 * @param entity
	 */
	public void remove(E entity);
	
	/**
	 * Synchronize persistent context with underlying database,
	 * useful for ORM implementations (JPA, Hibernate...).
	 * 
	 */
	public void flush();
	
	/**
	 * Merge entity to database. 
	 * 
	 * @param entity
	 * @return merged entity
	 */
	public E merge(E entity);
	
	/**
	 * Find entity by Long unique identifier.
	 * 
	 * @param id
	 * @return entity with corresponding unique id
	 */
	public E findEntity(Long id);
	
	/**
	 * Count entities in database.
	 * 
	 * @return count of all entities 
	 */
	public long countEntities();
	
	/**
	 * Returns all entities from database.
	 * 
	 * @return list with all entities 
	 */
	public List<E> findAllEntities();
	
	/**
	 * Returns entities in specified bounds.
	 * 
	 * @param firstResult
	 * @param maxResults
	 * @return list with entities in specified bounds 
	 */
	public List<E> findEntityEntries(int firstResult, int maxResults);
	
}
